﻿
// SaveTimeAssistantDlg.cpp: 实现文件
//

#include "stdafx.h"
#include "SaveTimeAssistant.h"
#include "SaveTimeAssistantDlg.h"
#include "afxdialogex.h"
#include<cstring>
#include<iostream>
#include<thread>
#include <string> 

#include <fstream>
#include <sstream>

#include<Windows.h>
#include<Tlhelp32.h>
#include<cstdlib>


#include "Psapi.h" //连接了库后引用头文件，EnumProcesses及GetModuleFileNameEx都需要引入这个头文件
#pragma comment(lib,"Psapi.lib") //预编译指令,连接psapi.lib库

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define GAME_BASE					0x00E851F8		//基址

#define GAME_BASE_P1				0x20		//基址 获取后偏移得到P1
#define GAME_BASE_P2				0x2c		//P1 获取后偏移得到人物基址

#define GAME_INFO_MAN_OFFSET_NAME	0xabc		//人物基址获取后偏移得到名字字符串地址



CString g_doctorName;
CString g_beBloodfedName;

using namespace std;
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_ABOUTBOX };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CSaveTimeAssistantDlg 对话框



CSaveTimeAssistantDlg::CSaveTimeAssistantDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_SAVETIMEASSISTANT_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

void CSaveTimeAssistantDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CSaveTimeAssistantDlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_DOCTOR_START, &CSaveTimeAssistantDlg::OnBnClickedButtonDoctorStart)
	ON_BN_CLICKED(IDC_BUTTON_StartTab, &CSaveTimeAssistantDlg::OnBnClickedButtonStarttab)
	ON_BN_CLICKED(IDC_BUTTON2, &CSaveTimeAssistantDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON_FreeLibrary, &CSaveTimeAssistantDlg::OnBnClickedButtonFreelibrary)
	ON_BN_CLICKED(IDC_BUTTON_meditation, &CSaveTimeAssistantDlg::OnBnClickedButtonmeditation)
END_MESSAGE_MAP()


void CSaveTimeAssistantDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void CSaveTimeAssistantDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CSaveTimeAssistantDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


UINT  myproc(LPVOID  lParam)
{
	CSaveTimeAssistantDlg *pWnd = (CSaveTimeAssistantDlg *)lParam;         //将窗口指针赋给无类型指针  
	pWnd->KMeansSegment();                         //要执行的函数  
	return 1;
}

UINT startUpdateDoctorInfo(LPVOID lParam) {
	CSaveTimeAssistantDlg *pWnd = (CSaveTimeAssistantDlg *)lParam;
	pWnd->updateDoctorInfo();
	return 1;
}

UINT startFindBeBLOodAdressFast(LPVOID lParam) {
	CSaveTimeAssistantDlg *pWnd = (CSaveTimeAssistantDlg *)lParam;
	pWnd->FindBeBLOodAdressFast();
	return 1;
}

long pInfoAdress;//医生角色地址
HANDLE gameProcess;

ComputerData doctorData;
ComputerData beBloodfedData;


int Pnum = 0, Cnum;//父窗口数量，每一级父窗口的子窗口数量  
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
	if (GetParent(hWnd) == NULL)
	{
		//&& IsWindowVisible(hWnd)  //如果判断是否顶层窗口并且可见加上该条件  
		Pnum++;
		Cnum = 0;
		char WindowTitle[100] = { 0 };
		DWORD dwPID = NULL;
		GetWindowThreadProcessId(hWnd, &dwPID);
		OutputDebugStringA("-------------------------------------------\n");

		::GetWindowTextA(hWnd, WindowTitle, 100);
		CStringA str;
		char title[] = "Element Client";
		if (strcmp(WindowTitle, title) == 0) {
			str.Format("%d: %s  hwnd:%x  pid:%x \n", Pnum, WindowTitle, hWnd, dwPID);
			OutputDebugStringA(str.GetString());

			ComputerData gameData;
			gameData.m_hWnd = hWnd;
			gameData.m_dwProcessId = dwPID;

			gameData.m_hProcess = ::OpenProcess(PROCESS_VM_READ, false, gameData.m_dwProcessId);

			long tempAdress = 0; //
			SIZE_T* readByte = NULL;
			ReadProcessMemory(gameData.m_hProcess, (LPVOID)(GAME_BASE), &tempAdress, 4, readByte);//一级地址读取
			ReadProcessMemory(gameData.m_hProcess, (LPVOID)(tempAdress + GAME_BASE_P1), &tempAdress, 4, readByte);//一级地址读取后偏移地址值读取后偏移读取二级地址值
			ReadProcessMemory(gameData.m_hProcess, (LPVOID)(tempAdress + GAME_BASE_P2), &tempAdress, 4, readByte);//一级地址读取后偏移地址值读取后偏移读取二级地址值
			ReadProcessMemory(gameData.m_hProcess, (LPVOID)(tempAdress + GAME_INFO_MAN_OFFSET_NAME), &tempAdress, 4, readByte);//一级地址读取后偏移地址值读取后偏移读取二级地址值
			ReadProcessMemory(gameData.m_hProcess, (LPVOID)(tempAdress), &gameData.Name, sizeof(gameData.Name), readByte);//一级地址读取后偏移地址值读取后偏移读取二级地址值

			if (_tcscmp(gameData.Name, L"希望这种距离") == 0) {
				doctorData = gameData;
			}
			if (_tcscmp(gameData.Name, L"90丶嚣张") == 0) {
				beBloodfedData = gameData;
			}

		//	if (_tcscmp(gameData.Name, L"123@whl") == 0) {
		//		doctorData = gameData;
		//	}
		//	if (_tcscmp(gameData.Name, L"想死过来找我") == 0) {
		//		beBloodfedData = gameData;
		//	}
		}
	}
	return true;
}


// CSaveTimeAssistantDlg 消息处理程序

BOOL CSaveTimeAssistantDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != nullptr)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码

	string path("config.txt");


	std::ifstream fin(path);
	while (!fin) {
		fin.close(); //也有别的办法可以让指针指到文件开头
		fin.open(path, std::ios::in);
		Sleep(100); //太快了有时候不行，不知道为什么
	}
	std::string line, res, PREHWND, sz2;


	string::size_type idx;


	CString str;
	DWORD dwPID = NULL;

	while (getline(fin, line)) {

		std::cout << line << '\n';
		PREHWND = "DoctorHWND:";

		idx = line.find(PREHWND);
		if (idx != string::npos) {
			line = line.substr(strlen(PREHWND.c_str()));
			std::cout << line << '\n';

			str = multiByteToWideChar(line);

			SetDlgItemText(IDC_EDIT2, str);

			/*	GetDlgItem(IDC_EDIT2)->GetWindowText(str);*/
			str.Insert(0, L"x");
			str.Insert(0, L"0");
			sz2 = CT2A(str.GetBuffer()); //转化为非unicode.
			int hwnd = std::stoi(sz2, nullptr, 0);

	
		}


		// 获取医生加血点击的X Y坐标值
		PREHWND = "DoctorAddBloodX:";
		idx = line.find(PREHWND);
		if (idx != string::npos) {
			line = line.substr(strlen(PREHWND.c_str()));
			std::cout << line << '\n';
			str = multiByteToWideChar(line);
			SetDlgItemText(IDC_EDIT_X, str);
		}

		// 获取医生玩家名称
		PREHWND = "DoctorName:";
		idx = line.find(PREHWND);
		if (idx != string::npos) {
			line = line.substr(strlen(PREHWND.c_str()));
			std::cout << line << '\n';
			g_doctorName = multiByteToWideChar(line);
		}

		PREHWND = "DoctorAddBloodY:";
		idx = line.find(PREHWND);
		if (idx != string::npos) {
			line = line.substr(strlen(PREHWND.c_str()));
			std::cout << line << '\n';
			str = multiByteToWideChar(line);
			SetDlgItemText(IDC_EDIT_Y, str);

		}

		// 获取被加血玩家名称
		PREHWND = "BeBloodfedName:";
		idx = line.find(PREHWND);
		if (idx != string::npos) {
			line = line.substr(strlen(PREHWND.c_str()));
			std::cout << line << '\n';
			g_beBloodfedName = multiByteToWideChar(line);
		}

		PREHWND = "BeBloodfedHWND:";
		idx = line.find(PREHWND);
		if (idx != string::npos) {
			line = line.substr(strlen(PREHWND.c_str()));
			std::cout << line << '\n';
			str = multiByteToWideChar(line);
			SetDlgItemText(IDC_EDIT_BEBLOODFED_HWND, str);
			str.Insert(0, L"x");
			str.Insert(0, L"0");
			sz2 = CT2A(str.GetBuffer()); //转化为非unicode.
			int hwnd = std::stoi(sz2, nullptr, 0);
		}

	}

	EnumWindows(EnumWindowsProc, NULL);

	fin.close();

	HWNDDoctor = doctorData.m_hWnd;//Doctor句柄

	//GetWindowThreadProcessId(HWNDDoctor, &dwPID);
	int lpid = doctorData.m_dwProcessId;

	gameProcessDoctor = doctorData.m_hProcess;
	str.Format(L"D:%d,X:%x", lpid, lpid);
	SetDlgItemText(IDC_STATIC_DOC_PID, str);


	HWND hWndBeBloodfed = (HWND)beBloodfedData.m_hWnd; // 窗口的句柄
	HWNDBeBloodfed = (HWND)beBloodfedData.m_hWnd;;//被加血句柄
	//GetWindowThreadProcessId(HWNDBeBloodfed, &dwPID);
	 lpid = beBloodfedData.m_dwProcessId;
	gameProcessBeBloodfed = beBloodfedData.m_hProcess;

	AfxBeginThread(startUpdateDoctorInfo, (LPVOID)this);//启动新的线程更新医生信息
	AfxBeginThread(startFindBeBLOodAdressFast, (LPVOID)this);//启动新的线程更新医生信息

	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}



bool isDoctorStart = false;


bool isBloodAdressFind = false;



// 更新被加血的人物信息
void CSaveTimeAssistantDlg::FindBeBLOodAdressFast() {
	//gameProcess = gameProcessBeBloodfed;
	if (NULL == gameProcessBeBloodfed) {
		MessageBoxA(0, "gameProcessDoctor = NULL", "gameProcessDoctor = NULL", 0);
	}

	CString str;
	SIZE_T* readByte = NULL;
	Man man;

	long baseAdress = 0x00E851F8;//一级地址
	long tempAdress = 0; //

	ReadProcessMemory(gameProcessBeBloodfed, (LPVOID)(baseAdress), &tempAdress, 4, readByte);//一级地址读取
	ReadProcessMemory(gameProcessBeBloodfed, (LPVOID)(tempAdress + 0x20), &tempAdress, 4, readByte);//一级地址读取后偏移地址值读取后偏移读取二级地址值
	ReadProcessMemory(gameProcessBeBloodfed, (LPVOID)(tempAdress + 0x2C), &tempAdress, 4, readByte);//一级地址读取后偏移地址值读取后偏移读取二级地址值

	beBloodfedInfoAddress = tempAdress;

	long bloodAdress = tempAdress + 0x294;

	ReadProcessMemory(gameProcessBeBloodfed, (LPVOID)(bloodAdress), &man.blood, 4, readByte);//获取血
	ReadProcessMemory(gameProcessBeBloodfed, (LPVOID)(bloodAdress + 0x4), &man.power, 4, readByte);//获取蓝
	str.Format(L"%d", man.blood);
	SetDlgItemText(IDC_STATIC_BeBloodfedHP, str);

	str.Format(L"%d", man.power);
	SetDlgItemText(IDC_STATIC_BeBloodfedMP, str);
}


// 更新医生的信息
void CSaveTimeAssistantDlg::updateDoctorInfo() {

	gameProcessDoctor = doctorData.m_hProcess;
	gameProcess = gameProcessDoctor;
	CString str;

	if (NULL == gameProcessDoctor) {
		MessageBoxA(0, "gameProcessDoctor = NULL", "gameProcessDoctor = NULL", 0);
	}

	DWORD blood, power, level;
	//LPDWORD readByte = NULL;
	SIZE_T* readByte = NULL;
	PFLOAT  far readfloat = NULL;

	Man man;

	long searchStartAddress = 0x07000000;
	long pBloodAdress;//血指针偏移地址


	long baseAdress = 0x00E851F8;//一级地址
	long tempAdress = 0; //
	long doctorBaseAdress = 0; //
	ReadProcessMemory(gameProcess, (LPVOID)(baseAdress), &tempAdress, 4, readByte);//一级地址读取
	ReadProcessMemory(gameProcess, (LPVOID)(tempAdress+ 0x20), &tempAdress, 4, readByte);//一级地址读取后偏移地址值读取后偏移读取二级地址值
	ReadProcessMemory(gameProcess, (LPVOID)(tempAdress+ 0x2C), &tempAdress, 4, readByte);//一级地址读取后偏移地址值读取后偏移读取二级地址值

	doctorBaseAdress = tempAdress;

	//查询选中目标相关的的信息




	while (1)
	{
		// 读取主人物的信息
		ReadProcessMemory(gameProcess, (LPVOID)(doctorBaseAdress), &pBloodAdress, 4, readByte);
		str.Format(L"%x", pBloodAdress);
		SetDlgItemText(IDC_EDIT_DOCTOR_INFO_ADRESS, str);
		long bloodAdress = tempAdress + 0x294;

		ReadProcessMemory(gameProcess, (LPVOID)(bloodAdress), &man.blood, 4, readByte);//获取血

		ReadProcessMemory(gameProcess, (LPVOID)(bloodAdress + 0x4), &man.power, 4, readByte);//获取蓝
		ReadProcessMemory(gameProcess, (LPVOID)(bloodAdress + 0x20), &man.maxBlood, 4, readByte);//获取血上限
		ReadProcessMemory(gameProcess, (LPVOID)(bloodAdress + 0x24), &man.maxPower, 4, readByte);//获取蓝上限


		long pBloodAdress = tempAdress + 0xaac;
		ReadProcessMemory(gameProcess, (LPVOID)(pBloodAdress), &man.x, 4, readByte);//获取x

		pBloodAdress = pBloodAdress + 0x4;
		ReadProcessMemory(gameProcess, (LPVOID)(pBloodAdress), &man.h, 4, readByte);//获取h

		pBloodAdress = pBloodAdress + 0x4;
		ReadProcessMemory(gameProcess, (LPVOID)(pBloodAdress), &man.y, 4, readByte);//获取z


		str.Format(L"%d", man.blood);
		SetDlgItemText(IDC_STATIC_DOC_HP, str);


		str.Format(L"%d", man.power);
		SetDlgItemText(IDC_STATIC_DOC_MP, str);

		str.Format(L"%f", man.x);
		SetDlgItemText(IDC_EDIT_DOC_X, str);

		str.Format(L"%f", man.h);
		SetDlgItemText(IDC_EDIT_DOC_H, str);

		str.Format(L"%f", man.y);
		SetDlgItemText(IDC_EDIT_DOC_Y, str);
		Sleep(200);
	}
}



//加血函数
void CSaveTimeAssistantDlg::KMeansSegment()
{
	CString str = L"004D0980";

	if (!isDoctorStart) {


		GetDlgItem(IDC_EDIT2)->GetWindowText(str);
		str.Insert(0, L"x");
		str.Insert(0, L"0");
		std::string sz2 = CT2A(str.GetBuffer()); //转化为非unicode.
		int hwnd = std::stoi(sz2, nullptr, 0);
		HWND hWnd = (HWND)hwnd; // 窗口的句柄


		str = L"00090EB4";

		GetDlgItem(IDC_EDIT_BEBLOODFED_HWND)->GetWindowText(str);
		str.Insert(0, L"x");
		str.Insert(0, L"0");
		sz2 = CT2A(str.GetBuffer()); //转化为非unicode.
		int hwndBeBloodfed = std::stoi(sz2, nullptr, 0);
		HWND hWndBeBloodfed = (HWND)hwndBeBloodfed; // 窗口的句柄


		DWORD dwPID = NULL;
		GetWindowThreadProcessId(hWndBeBloodfed, &dwPID);
		int lpid = dwPID;


		SetDlgItemText(IDC_BUTTON_DOCTOR_START, L"Stop");
		isDoctorStart = true;


		DWORD blood, power;
		//LPDWORD readByte = NULL;
		SIZE_T* readByte = NULL;
	


		HANDLE gameProcess = ::OpenProcess(PROCESS_VM_READ, false, lpid);


		long baseAdress = 0x00E851F8;//一级地址
		long tempAdress = 0; //
		long doctorBaseAdress = 0; //
		ReadProcessMemory(gameProcess, (LPVOID)(baseAdress), &tempAdress, 4, readByte);//一级地址读取
		ReadProcessMemory(gameProcess, (LPVOID)(tempAdress + 0x20), &tempAdress, 4, readByte);//一级地址读取后偏移地址值读取后偏移读取二级地址值
		ReadProcessMemory(gameProcess, (LPVOID)(tempAdress + 0x2C), &tempAdress, 4, readByte);//一级地址读取后偏移地址值读取后偏移读取二级地址值

		long bloodAdress = tempAdress + 0x294;

		GetDlgItem(IDC_EDIT_X)->GetWindowText(str);
		sz2 = CT2A(str.GetBuffer()); //转化为非unicode.
		doctorAddbloodX = std::stoi(sz2, nullptr, 0);


		GetDlgItem(IDC_EDIT_Y)->GetWindowText(str);
		sz2 = CT2A(str.GetBuffer()); //转化为非unicode.
		doctorAddbloodY = std::stoi(sz2, nullptr, 0);

		//char ttr[30];
		//sprintf_s(ttr, "doctorAddbloodX:%d,  doctorAddbloodY:%d", doctorAddbloodX, doctorAddbloodY);

		//OutputDebugStringA(ttr);
		while (isDoctorStart)
		{

			GetDlgItemText(IDC_STATIC_BeBloodfedHP, str);
			sz2 = CT2A(str.GetBuffer()); //转化为非unicode.
			blood = std::stoi(sz2, nullptr, 0);

			ReadProcessMemory(gameProcess, (LPVOID)(bloodAdress), &blood, 4, readByte);

			int pxy = doctorAddbloodY << 16 + doctorAddbloodX;

			if (200 < blood&& blood < 40197) {
	/*			::SendMessageA(hWnd, WM_LBUTTONDOWN, 0, MAKELPARAM(IDC_EDIT_X, doctorAddbloodY));
				::SendMessageA(hWnd, WM_LBUTTONUP, 0, MAKELPARAM(IDC_EDIT_X, doctorAddbloodY));	*/
				::SendMessageA(hWnd, WM_LBUTTONDOWN, 0, MAKELPARAM(doctorAddbloodX, doctorAddbloodY));
				::SendMessageA(hWnd, WM_LBUTTONUP, 0, MAKELPARAM(doctorAddbloodX, doctorAddbloodY));
			}
			str.Format(L"%d", blood);
			SetDlgItemText(IDC_STATIC_BeBloodfedHP, str);

			Sleep(300);
		}
	}
	else {

		isDoctorStart = false;

		SetDlgItemText(IDC_BUTTON_DOCTOR_START, L"Start");

	}

	// 主要处理函数在这里写  
}

void CSaveTimeAssistantDlg::OnBnClickedButtonDoctorStart()
{
	AfxBeginThread(myproc, (LPVOID)this);//启动新的线程  
	//SetWindowsHookEx()
}



DWORD GetProcessidFromName(WCHAR * name)
{
	PROCESSENTRY32 pe;
	DWORD id = 0;
	HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	pe.dwSize = sizeof(PROCESSENTRY32);
	if (!Process32First(hSnapshot, &pe))
		return 0;
	while (1)
	{
		pe.dwSize = sizeof(PROCESSENTRY32);
		if (Process32Next(hSnapshot, &pe) == FALSE)
			break;

		if (wcscmp(pe.szExeFile, name) == 0)
		{
			id = pe.th32ProcessID;

			break;
		}
	}
	CloseHandle(hSnapshot);
	return id;
}


void CSaveTimeAssistantDlg::OnBnClickedButtonStarttab()
{
	TCHAR __main_home__[MAX_PATH] = { 0 };
	char __main_home_ansi__[MAX_PATH] = { 0 };
	TCHAR szData[250] = { 0 };
	long l(0);
	GetModuleFileName(::AfxGetInstanceHandle(), __main_home__, MAX_PATH);
	for (l = lstrlen(__main_home__); l > 0 && __main_home__[l] != _T('\\'); __main_home__[l--] = 0);
	GetModuleFileNameA(::AfxGetInstanceHandle(), __main_home_ansi__, MAX_PATH);
	for (l = lstrlenA(__main_home_ansi__); l > 0 && __main_home_ansi__[l] != '\\'; __main_home_ansi__[l--] = 0);
	::SetCurrentDirectory(__main_home__);

	wcscat(__main_home__, L"MouseTEST.exe");


	int iSize;
	char* pszMultiByte;

	//返回接受字符串所需缓冲区的大小，已经包含字符结尾符'\0'
	iSize = WideCharToMultiByte(CP_ACP, 0, __main_home__, -1, NULL, 0, NULL, NULL); //iSize =wcslen(pwsUnicode)+1=6
	pszMultiByte = (char*)malloc(iSize * sizeof(char)); //不需要 pszMultiByte = (char*)malloc(iSize*sizeof(char)+1);
	WideCharToMultiByte(CP_ACP, 0, __main_home__, -1, pszMultiByte, iSize, NULL, NULL);


	if (GetProcessidFromName(L"MouseTEST.exe") == 0)
	{
		ShellExecuteA(0, "open", "MouseTEST.exe", 0, 0, 0);

		SetDlgItemText(IDC_BUTTON_StartTab, L"StopTab");
	}
	else {

		HWND  thwnd = FindWindowA("ConsoleWindowClass", pszMultiByte); //寻找窗口
		::SendMessageA(thwnd, WM_CLOSE, 0, 0);
		SetDlgItemText(IDC_BUTTON_StartTab, L"StartTab");

	}

}

HMODULE ModuleHandle = NULL;
BOOL    bOk = FALSE;
FARPROC    FunctionAddress = NULL;
DWORD  dwThreadId = 14684;
HHOOK   g_hHook = NULL;
PVOID   pShareM = NULL;

void CSaveTimeAssistantDlg::OnBnClickedButton2()
{

	ModuleHandle = LoadLibrary(L"GameDLL.dll");


	if (NULL == ModuleHandle)
	{
		MessageBoxA(NULL, "模块失败", "失败", 0);
	}
	//FunctionAddress = (FARPROC)GetProcAddress(ModuleHandle, "MyMessageProcess");



	//g_hHook = SetWindowsHookEx(
	//	WH_GETMESSAGE,//WH_KEYBOARD,//WH_CALLWNDPROC,
	//	(HOOKPROC)FunctionAddress,
	//	ModuleHandle,
	//	dwThreadId
	//);


	//ModuleHandle = LoadLibrary(L"DllGame.dll");
	FunctionAddress = (FARPROC)GetProcAddress(ModuleHandle, "dazuo");

	if (NULL == FunctionAddress)
	{
		MessageBoxA(NULL, "方法失败", "失败", 0);
	}

	DWORD writeByte = NULL;

	HANDLE gameProcessDazuo = gameProcessDoctor;//dazuo进程

	//运行Call相关

	LPVOID CallAddr = VirtualAllocEx(gameProcessDazuo, NULL, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);

	if (CallAddr == NULL)
	{
		MessageBoxA(GetSafeHwnd(), "CallAddr失败", "错误", 0);
		CloseHandle(gameProcessDazuo);
	}

	//g_hHook = SetWindowsHookEx(
	//	WH_KEYBOARD,//WH_KEYBOARD,//WH_CALLWNDPROC,
	//	(HOOKPROC)FunctionAddress,
	//	ModuleHandle,
	//	dwThreadId
	//);

	//dwThreadId = GetProcessidFromName(L"elementclient.exe");

	//g_hHook = SetWindowsHookExA(WH_KEYBOARD, (HOOKPROC)FunctionAddress, ModuleHandle, 0);

	//if (g_hHook == NULL) {
	//	MessageBoxA(NULL, "失败", "失败", 0);
	//}


	// TODO: 在此添加控件通知处理程序代码
}


void CSaveTimeAssistantDlg::OnBnClickedButtonFreelibrary()
{
	if (ModuleHandle)
		FreeLibrary(ModuleHandle);
	::UnhookWindowsHookEx(g_hHook);
	// TODO: 在此添加控件通知处理程序代码
}


void dazuo() {

	//toDazuoInfoAddress
	__asm
	{
		push 00040401
		mov ecx, 0x00E851F8
		mov ecx, [ecx]
		add ecx, 20
		mov ecx, [ecx]
		add ecx, 0x2c
		mov ecx, [ecx]
		mov ebx, 00473670
		call ebx
	}
}

BOOL EnableDebugPrivilege()
{

	HANDLE TokenHandle = NULL;
	TOKEN_PRIVILEGES TokenPrivilege;
	LUID uID;

	//打开权限令牌
	if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &TokenHandle))
	{
		return FALSE;
	}

	if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &uID))
	{

		CloseHandle(TokenHandle);
		TokenHandle = INVALID_HANDLE_VALUE;
		return FALSE;
	}

	TokenPrivilege.PrivilegeCount = 1;
	TokenPrivilege.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
	TokenPrivilege.Privileges[0].Luid = uID;

	//在这里我们进行调整权限
	if (!AdjustTokenPrivileges(TokenHandle, FALSE, &TokenPrivilege, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
	{
		CloseHandle(TokenHandle);
		TokenHandle = INVALID_HANDLE_VALUE;
		return  FALSE;
	}

	CloseHandle(TokenHandle);
	TokenHandle = INVALID_HANDLE_VALUE;
	return TRUE;
}


void CSaveTimeAssistantDlg::OnBnClickedButtonmeditation()
{
	if (!EnableDebugPrivilege()) {
		MessageBoxA(NULL, "提权成功", "失败", 0);
	}

	ModuleHandle = LoadLibrary(L"dllmain.dll");


	if (NULL == ModuleHandle)
	{
		MessageBoxA(NULL, "模块失败", "失败", 0);
	}

	FunctionAddress = (FARPROC)GetProcAddress(ModuleHandle, "getDllPoint");

	if (NULL == FunctionAddress)
	{
		MessageBoxA(NULL, "方法失败", "失败", 0);
	}


	SIZE_T writeByte = NULL;

	HANDLE gameProcessDazuo = gameProcessDoctor;//dazuo进程

	//运行Call相关

	LPVOID CallAddr = VirtualAllocEx(gameProcessDazuo, NULL, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);

	if (CallAddr == NULL)
	{
		MessageBoxA(GetSafeHwnd(), "CallAddr失败","错误",0);
		CloseHandle(gameProcessDazuo);
	}
	if (!WriteProcessMemory(gameProcessDazuo, CallAddr, FunctionAddress, MAX_PATH, &writeByte)) {
		MessageBoxA(GetSafeHwnd(), "写入函数失败", "错误", 0);
	}

	LPTHREAD_START_ROUTINE FunctionAddress = NULL;

	FunctionAddress = (PTHREAD_START_ROUTINE)::GetProcAddress(::GetModuleHandle(_T("Kernel32")), "LoadLibraryW");

	LPDWORD w = (LPDWORD) writeByte;

	CreateRemoteThread(gameProcessDazuo, NULL, 0, FunctionAddress, CallAddr, 0, w);

	VirtualFreeEx(gameProcessDazuo, NULL, MAX_PATH, MEM_COMMIT | MEM_RESERVE);

	// TODO: 在此添加控件通知处理程序代码
}
